package com.voute.Base;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.voute.App.App;
import com.voute.Utils.PreferenceUtils;
import com.voute.View.Activity.RegisterActivity;
import com.zxinsight.MLink;
import com.zxinsight.MagicWindowSDK;

/**
 * Activity基础类库
 * Created by liukanshan on 2016/12/8.
 */

public abstract class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        setupView();
        setupData();
        App.GetInstance().addActivity(this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Uri mLink = getIntent().getData();
        if (mLink != null) {
            MagicWindowSDK.getMLink().router(mLink);
        } else {
            MLink.getInstance(this).checkYYB();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
//        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
//        MobclickAgent.onPause(this);
    }

    public abstract int getLayoutId();

    public abstract void setupView();

    public abstract void setupData();

    public <T extends View> T $(int id) {
        return (T) super.findViewById(id);
    }

    protected void hidenInput(View view) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    public boolean checkLoginStatus() {
        if (TextUtils.isEmpty(PreferenceUtils.GetUserToken())) {
            Intent intent = new Intent(this, RegisterActivity.class);
            this.startActivity(intent);
            return false;
        }
        return true;
    }
}
